home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor2 / csim261.doc < prev    next >
Text File  |  1995-03-31  |  28KB  |  642 lines

  1. (Comp.sources.hp48) 
  2. Item: 52 by perre@picea 
  3. Author: [Per Stenius] 
  4.   Subj: Circut Simulator v2.61 
  5.   Date: Sun Feb 16 1992 
  6.  
  7. Csim 2.61 SHORT DESCRIPTION AND MANUAL 12/17/91 (c) Per Stenius 
  8.  
  9. RELEASE NOTE 
  10.  
  11. This version differs from the previous (2.3, 2.5, 2.51, 2.6) in the 
  12. following: 
  13. Version 2.3: 
  14. - Lossless transmission line for AC analysis at a single freq. point. (T) 
  15. - The functions CV(node) and CI(branch) that fetch the voltage/current of 
  16.   given node/branch in the previous solution point. CV = ControlVoltage, 
  17.   can be used in other sources to define any functional dependency of a 
  18.   voltage/current in the circuit. Note that there is a delay of 'tstep' 
  19.   when using these functions. 
  20. - The program 'iterdc' for iterative dc solving to be used with nonlinear 
  21.   components. 
  22. - Additional examples of circuits in manual. 
  23. - New sample circuit. 
  24. Version 2.5, 2.51, (and previous versions): 
  25. - ABCD-matrix for two-port added. 
  26. - Minor changes in code for improved speed (during setup) 
  27. - BOTH NODES GND error removed, BOTH NODES SAME used instead. 
  28. Version 2.6 (and previous): 
  29. - ABCD, y and z matrix two-ports can be used in DC analysis if all matrix 
  30.   elements are real (i.e. the imaginary part must be zero) 
  31. - A->L converts array into list (for easier handling of matrices) 
  32.  
  33. INTRODUCTION 
  34.  
  35. This text describes a simple circuit simulator called Csim for the HP48. 
  36. It makes DC, AC and transient simulations and supplies the user with all 
  37. matrices used. The method used is modified nodal analysis, and thus 
  38. elements such as an inductor or ideal voltage source require that a current 
  39. branch is also specified together with the nodes. As soon as a setup is 
  40. done, single analyses can be made with the 'dc', 'ac' or 'tran' sub- 
  41. programs. All subprograms return the result as a vector, whereas Csim 
  42. provides the user with a plot in transient and AC analysis. Note that for 
  43. Csim to work correctly, the 'node' variable should be defined (either a 
  44. node or branch number) when plotting a result. Note also that the RES 
  45. variable (in PLOTR) should be 0. Finally, if SYM (in MODES) is not set 
  46. Csim does not work correctly. 
  47.  
  48. For a demo on how Csim works do the following: 
  49. - download the code (creates the directory CSIM in the current directory) 
  50. - enter the directory CSIM and enter the custom menu (the button marked CST 
  51.   between the PRG and VAR buttons on your HP48) 
  52. - press [Csim]: 
  53.   for: Setup? Y  press: <enter> 
  54.   for: Analysis? (D,A,T) press: T <enter> 
  55.   for: Sweep range? 
  56.        :tstart:0 
  57.        :tstep:0 
  58.        :tstop:1          press: <backspc> 5 <enter> i.e. :tstop:5 
  59.   after which a time-domain plot is drawn (if you have something that 
  60.   you previously have plotted, press [CLRSC] before doing this). 
  61.   Press <ON> to exit the graph environment. 
  62.   Now, press 3 <left-shft> [node] <enter> and redo the above ([node] is 
  63.   a variable in the custom menu). 
  64.   Finally, press the CST button, <next> [CIR] [CIR->] to see the circuit 
  65.   description. 
  66.  
  67. Here is an explanation on the custom menu of Csim (the custom menu is 
  68. obtained by pressing the button marked CST on your HP48, and contains 
  69. those variables and programs you need for using Csim): 
  70.  
  71. Csim - the simulator program. Runs setup (if requested) and a single 
  72.         analysis. For ac, a single run directly from the custom menu 
  73.         provides a fast solution in one freq-point. When choosing T 
  74.         for transient analysis either tstep (time resolution) or tstop 
  75.         should be given. If both are given tstep is used and tstop 
  76.         ignored. 
  77.  
  78. View  - the StackView application, for easy check on components. Use 
  79.         ATTN (ON) to exit. You can also use the Interactive Stack the 
  80.         HP48 provides (see manual p.70). 
  81.  
  82. node  - the node or branch the value of which is wanted as a solution. 
  83.         Used to GET the right value from the solution vector. 
  84.  
  85. ymin, ymax 
  86.       - define the picture y-axis (ac or tran analysis) 
  87.  
  88. CLRSC - Clears the screen (simply the ERASE command) 
  89.  
  90. outp  - a program that takes a vector from the stack and returns one value. 
  91.         it can be used to plot a result that is a function of the values 
  92.         in the solution vector. To be edited by the user. 
  93.         (default << node GET >> ) 
  94.  
  95. CIR-> - takes a list of lists, such as the one used to store circuit 
  96.         descriptions (see also CIR, ->CIR) and puts the lists in it to 
  97.         the stack (inverse to ->CIR). Usage: Press a variable containing 
  98.         a circuit description (e.g. CIR) and press CIR->. 
  99.  
  100. ->CIR - takes the circuit description used by Csim and puts it to a list, 
  101.         that can be stored in a variable. 
  102.  
  103. CIR   - when 'Setup' is run, the stack containing the circuit is stored in 
  104.         this variable as a list. To use again, recall CIR and run 'CIR->'  
  105.         (see above). Contains a sample circuit as default. Any circuit 
  106.         description can be stored in a variable as a list of components 
  107.         (which also are lists). 
  108.  
  109. dc    - single DC analysis.  Requires that setup is done (the matrices are 
  110.         ready). Takes no argument from stack and returns a solution vector. 
  111.  
  112. ac    - single AC analysis. Requires that setup is done (the matrices are 
  113.         ready) and that 'w' is specified (rads/s angular freq). Takes no 
  114.         argument from stack and returns a solution vector. Note: Complex 
  115.         values! When A is chosen in Csim, the actual program stored by STEQ 
  116.         is 'acplot', which executes 'ac' and then 'outp'. The program 
  117.         'outp' should take a vector from stack and return a single number. 
  118.         E.g. << node GET ABS >> would return the absolute value of a node 
  119.         voltage (or branch current) that is to be plotted. 
  120.  
  121. A->L  - converts an array into a list. 
  122.  
  123. tran  - single transient analysis. Takes one time step and returns a 
  124.         solution vector. The method used is trapezoidal rule. When T is 
  125.         chosen in Csim, the actual program stored by STEQ is 'tranBE' (or 
  126.         'tranTR'). These return the result vector and call 'outp'. The 
  127.         program 'outp' should take a vector from stack and return a single 
  128.         number. E.g. << node GET >> would return the value of a node voltage 
  129.         (or branch current) that is to be be plotted. 
  130.  
  131. Setup - setup routine for the simulator. Creates and loads the matrices 
  132.         needed and stores the stack as a list into CIR. Takes the circuit 
  133.         description from the stack as an argument (only component declara- 
  134.         tions are allowed on stack). Setup must be done once before analy- 
  135.         zing, however, after that the matrices are ready to be used multi- 
  136.         ple times. This should be remembered e.g. when calculating a DC 
  137.         solution and thereafter starting a transient analysis from the 
  138.         obtained results. In this case running Setup a second time would 
  139.         zero the result vector. Setup also clears flag -3 (i.e. enables 
  140.         SYM), sets flag -17 and clears flag -18 (i.e. sets radians mode). 
  141.  
  142. w     - angular frequency (2*pi*f) rad/s. 
  143.  
  144. G     - conductance matrix. Contains all real valued entries, i.e. those 
  145.         caused by elements the values of which do not have an s or jw 
  146.         factor. 
  147.  
  148. C     - s-matrix. Contains all elements that have an s or jw factor. 
  149.  
  150. Cc    - constant valued complex matrix. Can be used in AC analysis only, 
  151.         at a single value of 'w' (angular frequency). Contains entries 
  152.         from Z, Y, z, y (See Section on syntax). 
  153.  
  154. W     - numerical values of the sources as a vector. This vector is 
  155.         updated in every analysis point. 
  156.  
  157. Wlist - the functions representing each source as a list, from which 
  158.         the numerical values for 'W' are obtained. 
  159.  
  160. Euler - specifies the method used in the tran analysis. If Euler = 1 then 
  161.         backward Euler ('tranBE') is used (faster but more inaccurate), if 
  162.         Euler = 0 then the trapezoidal rule is used, which is rather 
  163.         accurate but slower ('tranTR' and 'tran'). 
  164.  
  165. iterdc 
  166.       - if CV() or CI() are used in DC analysis, iterative solution is 
  167.         required in order to obtain the correct solution. 'iterdc' can 
  168.         be used for this after setup has been done. Note that very few 
  169.         nonlinear circuits can actually be solved by iteration only. 
  170.         Usually some linearization method must also be used, e.g. the 
  171.         Newton-Raphson algorithm. Giving good initial guesses for node 
  172.         voltages and branch currents in the X vector also helps. 
  173.  
  174. THE SYNTAX USED TO DESCRIBE A CIRCUIT 
  175.  
  176. The syntax by which the components are entered is (NOTE! Each circuit 
  177. needs a ground node and its number is always 0 (zero)): 
  178.   
  179. {R node1 node2 numval branch} - resistance [ohm] 
  180.  
  181. {G node1 node2 numval}        - conductance [mho] 
  182.  
  183. {C node1 node2 numval}        - capacitance [F] 
  184.  
  185. {L node1 node2 numval branch} - inductance [H] 
  186.  
  187. {Y node1 node2 complexnumval} - admittance with a constant complex value 
  188.                                 (re,im). In DC analysis each entry must 
  189.                                 be real (im = 0). 
  190.  
  191. {Z node1 node2 complexnumval} - impedance with a constant complex value 
  192.                                 (re,im) In DC analysis each entry must 
  193.                                 be real (im = 0). 
  194.  
  195. {J node1 node2 funcval}       - indep. current source 
  196.  
  197. {E node1 node2 funcval branch} 
  198.                               - indep. voltage source   
  199.  
  200. {S node1 node2 branch}        - short circuit (the current is fetched by 
  201.                                 branch GET). Can be used to define a current 
  202.                                 branch for dependent sources. 
  203.  
  204. {O in+ in- out+ out- outbranch} 
  205.                               - ideal opamp (out- should be ground, 
  206.                                 outbranch returns the output current) 
  207.  
  208. {M l1node1 l1node2 l2node1 l2node2 l1val l2val mval l1branch l2branch} 
  209.                               - transformer i.e. two inductors (l1, l2) with 
  210.                                 mutual inductance (mval). The values required 
  211.                                 are the four nodes, the value of l1, l2, mval 
  212.                                 [H] and the branches of l1 and l2. The dots  
  213.                                 for m are at l1node1 and l2node1. 
  214.  
  215. {m l1branch l2branch mval}    - mutual inductance of mval [H]. As M, but can 
  216.                                 be used to define e.g. three inductances 
  217.                                 that all have mutual inductances. To do 
  218.                                 this, define the 3 L:s and then 3 m:s be- 
  219.                                 tween them. Note that m takes the branches 
  220.                                 of the L:s. Make sure you specify the in- 
  221.                                 ductors the right way (the branch of L runs 
  222.                                 from n1 to n2). Note also that m is not a 
  223.                                 component, it merely states a dependency 
  224.                                 between two L:s that should be defined se- 
  225.                                 parately. No checking is done that l1branch 
  226.                                 and l2branch actually belong to L:s. 
  227.  
  228. {T node1 node2 node3 node4 llval Zoval} 
  229.                               - lossless transmission line (to be used in AC 
  230.                                 analysis only) of length ll (in wavelengths) 
  231.                                 and with the characteristic impedance Zo. 
  232.                                 Note that nodes 2 and 4 must have the same 
  233.                                 value (equivalent pi-circuit used). 
  234.  
  235. {g node1 node2 node3 node4 numval} 
  236.                               - voltage-controlled current source i.e. 
  237.                                 transconductance. The source current is 
  238.                                 from node3 to node4 and the controlling 
  239.                                 voltage from node1 to node2. 
  240.  
  241. {r node1 node2 node3 node4 numval branch1 branch2} 
  242.                               - current-controlled voltage source. Defines 
  243.                                 a short circuit between node1 and node2 
  244.                                 and a controlled voltage source between 
  245.                                 node3 and node4 (node3 being the positive 
  246.                                 node). The controlling current runs through 
  247.                                 branch1 and the current of the source is 
  248.                                 fetched from branch2. Branch1 must not be 
  249.                                 a previously defined branch. 
  250.  
  251. {p node3 node4 numval branch1 branch2} 
  252.                               - same as r but does not define a short 
  253.                                 circuit between node1 and node2. Instead 
  254.                                branch1 must be a predefined branch (e.g. 
  255.                                 that of a resistor or inductor).  
  256.   
  257. {a node1 node2 node3 node4 numval branch} 
  258.                               - current-controlled current source. Defines 
  259.                                 a short circuit between node1 and node2 
  260.                                 and a controlled current source the current 
  261.                                 of which runs from node3 to node4. The 
  262.                                 controlling current runs through branch 
  263.                                 which must not be previously defined. 
  264.                                  
  265. {b node3 node4 numval branch} - same as a but does not define a short 
  266.                                 circuit between node1 and node2. Instead 
  267.                                 branch must be a predefined branch (e.g. 
  268.                                 that of a resistor or inductor). Compare 
  269.                                 with p. 
  270.  
  271. {u node1 node2 node3 node4 numval branch} 
  272.                               - voltage-controlled voltage source. The 
  273.                                 current through the source is fetched 
  274.                                 from branch. 
  275.  
  276. {y node1p1 node2p1 node1p2 node2p2 y11 y12 y21 y22} 
  277.                               - a two-port with y-parameters that are 
  278.                                 constant complex values (re,im). In DC 
  279.                                 analysis each entry must be real (im = 
  280.                                 0). 
  281.  
  282. {z node1p1 node2p1 node1p2 node2p2 z11 z12 z21 z22} 
  283.                               - a two-port with z-parameters that are 
  284.                                 constant complex values (re,im). In DC 
  285.                                 analysis each entry must be real (im = 
  286.                                 0). 
  287. {A node1p1 node2p1 node1p2 node2p2 A B C D} 
  288.                               - a two-port with ABCD-parameters that 
  289.                                 are constant complex values (re,im). 
  290.                                 In DC analysis each entry must be real 
  291.                                 (im = 0). 
  292. FUNCTIONS 
  293.  
  294. CV(node)                      - returns previously calculated value of 
  295.                                 the voltage of node. In code << X node 
  296.                                 GET >> 
  297.  
  298. CI(branch)                    - returns previously calculated value of 
  299.                                 the current of branch. In code << X 
  300.                                 branch GET >>, the same as CV(). 
  301.  
  302. In the above, nodes and branches are integer numbers. The ground node is 
  303. represented by 0. All nodes and branches should have a unique number and 
  304. they should be given in order e.g. nodes 0,1,2,3 and branches 4,5,6. These 
  305. numbers refer DIRECTLY to the position in the matrices/vectors. Thus the 
  306. 4'th element in the result vector would be the current through branch 4 and 
  307. the first element is the voltage of node 1. To help remembering the syntax, 
  308. you could e.g. have a variable y with the following contents: 
  309.  
  310. {y n1p1 n2p1 n1p2 n2p2 y11 y12 y21 y22} 
  311.  
  312. NOTE: The two-port y, z and ABCD parameters are valid in DC analysis ONLY 
  313. IF ALL THE ENTRIES in the corresponding matrix are real. 
  314.  
  315. The following components form equivalent circuits: 
  316.  
  317. {S 1 2 5} 
  318. {p 3 4 100 5 6} is the same as 
  319.  
  320. {r 1 2 3 4 100 5 6}, 
  321.  
  322. {S 1 2 5} 
  323. {b 3 4 100 5} is the same as 
  324.  
  325. {a 1 2 3 4 100 5}, 
  326.  
  327. {L 1 2 0.1 5} 
  328. {L 3 4 0.2 6} 
  329. {m 5 6 0.05} is the same as 
  330.  
  331. {M 1 2 3 4 0.1 0.2 0.05 5 6}. 
  332.  
  333. Finally, an example of usage for transient analysis: 
  334. (This is how your stack should look) 
  335.  
  336. {E 1 0 '10*SIN(10*t)' 4} 
  337. {C 1 2 0.01} 
  338. {L 2 3 1 5} 
  339. {R 3 0 10 6} 
  340.  
  341. This defines a RLC-circuit with nodes 1,2,3 (and ground) and current 
  342. branches 4,5,6. The current through branch 4 is equal to the current 
  343. through the ideal voltage source E, the current through branch 5 equals 
  344. the current through the inductor L, and the current through branch 6 
  345. equals the current through the resistor R. The values of the components 
  346. (which ALWAYS must be numerical) are 10 ohms, 1 henry and 0.01 farads. 
  347. The voltage source has a time-dependent value (used in transient analysis). 
  348. If 'node' is set to 3 the voltage over the resistor R is plotted in 
  349. transient analysis. On the other hand, 'outp' could be written as << DUP 
  350. 1 GET SWAP 2 GET - >> to return the voltage between nodes 1 and 2 as a 
  351. result. Note that sources (E,J) may have functional values (should be 
  352. suitable for the analysis requested! Time dependency for transient 
  353. analysis and 'w' dependency (angular freq) for AC). When running Csim, 
  354. the stack may ONLY contain component declarations! 
  355.  
  356. Press the CST button and then [View]. Now press ATTN (low-left corner, i.e. 
  357. ON). Press [Csim], press <enter> on "Setup? Y", press D (or T), <enter> on 
  358. analysis.   
  359.  
  360. An example for AC analysis (using A in Csim): 
  361.  
  362. {E 2 0 1 3} 
  363. {G 2 1 1} 
  364. {C 1 0 1} 
  365.  
  366. Set 'node' equal to 1 and write 'outp' equal to << node GET ABS >>. Se- 
  367. lect A on analysis and choose wstart 0 and wstop 10 (ymin = 0, ymax = 1). 
  368.  
  369. Another example for AC analysis (using 'w' = 1 and 'ac'): 
  370.  
  371. {J 0 1 10} 
  372. {G 3 0 1} 
  373. {G 2 0 1} 
  374. {Z 1 0 (0,-1)} 
  375. {M 3 1 2 1 2 1 0.5 4 5} 
  376.  
  377. Setup 
  378. 1 left-shft w ac 
  379.  
  380. The currents through the transformer are the 4'th and 5'th elements in the 
  381. result vector. Here's an example involving a transistor for which we have 
  382. the y-parameters y11 = 0.001, y12 = -j0.0001, y21 = 0.1 and y22 = 0.0001. 
  383. Its base is at node 1, emitter at gnd (node 0) and collector at node 2. 
  384.  
  385. {J 0 1 1} 
  386. {Z 1 0 1E3}       @ resistance of 1 kohms 
  387. {Z 2 0 1E3} 
  388. {Z 1 2 (0,-1000)} @ capacitance of -j1000 ohms 
  389. {y 1 0 2 0 1E-3 (0,-1E-4) 0.1 1E-4} 
  390.  
  391. Setup 
  392. ac 2 GET ABS (returns |Uo/Jin| = 884.035 V/A) 
  393.  
  394. For the use of the lossless transmission line we have the following ex- 
  395. ample (analysis can be made at a single frequency point only, at which ll 
  396. is valid): 
  397.  
  398. {J 0 1 1} 
  399. {Z 2 0 (75,-69)} 
  400. {T 1 0 2 0 0.583 50} 
  401.  
  402. Setup ac 1 GET 
  403.  
  404. returns (25.2092, -34.5800) which is the input impedance (J = 1) of a loss- 
  405. less transmission line of the length 0.583 wavelengths (at some frequency) 
  406. and with the characteristic impedance of 50 ohms, terminated with a load of 
  407. (75,-69) ohms. 
  408.  
  409. DC analysis: 
  410.  
  411. {J 0 1 1} 
  412. {R 1 0 1E3 3} 
  413. {p 2 0 10 3 4} 
  414.  
  415. The voltage of node 2 (the 2'nd element in the result vector) should be 
  416. 10V. The current through the controlled voltage source should be 0A (the 
  417. 4'th element in the result vector). 
  418.  
  419. For iterative DC solving of  circuits, consider these two examples: 
  420.  
  421. {E 1 0 1 3} 
  422. {G 1 0 1} 
  423. {G 1 2 1} 
  424. {J 0 2 'SQ(CV(1))'} 
  425.  
  426. and 
  427.  
  428. {J 0 1 1} 
  429. {G 1 0 1} 
  430. {G 1 2 1} 
  431. {E 2 0 'SQ(CV(1))' 3} 
  432.  
  433. Setup iterdc 
  434.  
  435. The first circuit converges after only two iterations, but the second one 
  436. requires several hundred to reach the exact solution ([[1] [1] [0]] in the 
  437. second case). Good initial guesses may help, and also the use of e.g. the 
  438. Newton-Raphson algorithm (see Vlach-Singhal; Computer Methods for Circuit 
  439. Analysis and Design). Note that 'iterdc' should actually also be used at 
  440. every time step in transient analysis to avoid the delay when using CV() 
  441. and CI(). 
  442.  
  443. A simple small signal model for a transistor (B-1 C-2 E-3): 
  444.  
  445. {R 1 3 1E3 4} 
  446. {G 2 3 0.0001} 
  447. {b 2 3 100 4} 
  448.  
  449. A voltage source used as an digital inverter; if the voltage of node 2 is 
  450. higher than 2.5 volts, then the voltage of node 3 is 0 volts, otherwise 
  451. 5 volts (note that there is a delay of one 'tstep'). 
  452.  
  453. {E 3 0 'IFTE(CV(2)>2.5,0,5)' 4} 
  454.  
  455. Including nonlinear components as such would make solving the matrix equ- 
  456. ation system a tedious process. It would also make the analysis MUCH slower. 
  457. However, it could be done. 
  458.  
  459. ERROR MESSAGES 
  460.  
  461. These are the only error messages in this program. Note that there are not 
  462. many error checking routines provided, so the user should be careful when 
  463. entering the circuit description. For any strange behaviour or false re- 
  464. sults, please email me directly and explain what occurred. 
  465.  
  466. SYNTAX ERROR - an error occurred in 'Setup' while Csim was loading the 
  467.                matrices. Check the circuit description and the component 
  468.                that is first on stack. See also section on syntax. 
  469.  
  470. NEGATIVE NODE NO. - a negative number was given as a node number. Check the 
  471.                the first component on stack. 
  472.  
  473. BOTH NODES SAME - a component was specified having two nodes that were the 
  474.                same value. To override this, use a short-circuit (S) between 
  475.                these nodes. 
  476.  
  477. ZERO VALUE OR BRANCH - a component with a value of zero was given or its 
  478.                branch number was zero (which is reserved for the ground 
  479.                node). 
  480.  
  481. n2 MUST EQUAL n4 IN T - you have entered a transmission line in the circuit 
  482.                with nodes 2 and 4 not equal. This is not allowed since the 
  483.                equivalent pi-circuit to the transmission line is actually 
  484.                used. 
  485. Im{Cc} \=/ 0 IN DC - you have specified components with complex values in 
  486.                DC analysis. 
  487.  
  488. A good way to avoid errors is to proceed systematically, e.g. in the 
  489. following way: 
  490.  
  491. 1) Choose one reference node to be ground (GND) and set its node number 
  492.    to 0. 
  493.  
  494. 2) Assign the rest of the nodes a number each, in numerical order: 
  495.    1,2,3,... 
  496.  
  497. 3) Find all the components that require a branch and assign each required 
  498.    branch a number starting from the highest node number plus one. 
  499.  
  500. !) The node and the branch numbers should follow eachother in numerical 
  501.    order, with no 'gaps' in between (e.g. 0,1,2 are nodes and 3,4 are 
  502.    branches). 
  503.  
  504. 4) Enter the circuit description component by component. Note that the 
  505.    stack should only contain component descriptions! Check your stack 
  506.    with 'View'. 
  507.  
  508. 5) Decide what results you need and edit 'outp' if necessary. Also, set 
  509.    'node' to the correct value. 
  510.  
  511. 6) Run 'Setup' once and start analyzing! Remember to run 'Setup' whenever 
  512.    you change your circuit or want to start from zero. Sometimes all you 
  513.    need to do is to edit your X vector.  
  514.  
  515. FREQUENTLY ASKED QUESTIONS 
  516.  
  517. Some people have had trouble with the branch currents (the direction...) 
  518. so here's more on that: 
  519.  
  520. In all components (J,E,L etc.) the current is defined to be FROM the first 
  521. node TO the second node. Thus no matter which way you put your source (E) 
  522. The value of the branch current remains the same (i.e. in the direction of 
  523. the U of the source) with respective to the source. In the sample RLC 
  524. circuit, when the first node of E and L is the same, the currents should 
  525. be the opposite. When the second node of E is the first node of L, the 
  526. currents are the same. 
  527.  
  528. For E the situation looks like this: 
  529.  
  530.            --- U=E --> 
  531.  
  532.  node1 +  o->-( E )---o - node2 
  533.  
  534.             I 
  535.  
  536. for L: 
  537.  
  538.            --- U1,2 -> 
  539.  
  540.  node1    o->- Ind ---o   node2 
  541.  
  542.             I 
  543.  
  544. for J: 
  545.  
  546.  node1    o->-( J )---o   node2 
  547.  
  548.             I=J 
  549.  
  550. for S:     
  551.  
  552.            --- U=0 --> 
  553.  
  554.  node1    o----->-----o   node2 
  555.  
  556.                 I 
  557.  
  558. This could be defined the other way around too, but in this case it isn't. 
  559.  
  560. For two-ports, the node numbers are defined as 
  561.  
  562.                 _________ 
  563.  node1    o->--|         |--<-o node3 
  564.                |         |              
  565.                |         | 
  566.                |         |   
  567.                |         | 
  568.  node2    o----|_________|----o node4 
  569.  
  570. Note that the direction of the currents is always towards the two-port. 
  571. This should be remembered when defining e.g. ideal opamps, controlled 
  572. sources and two-ports with y- or z-parameter representation. 
  573.  
  574. >I can't get the transient analysis to work properly unless I do 
  575. >an entire setup first. If I do a transient plot, and then repeat it, I 
  576. >get different results, unless I run setup. 
  577.  
  578. What happens is that unless you run setup, the transient analysis continues 
  579. from where it stopped (however, this time from the beginning of the screen). 
  580. Thus the new beginning should match with the previous end. As you might 
  581. have noticed, the transient analysis should always start from time=0. This 
  582. is due to the fact that solving this problem is an iterative process. 
  583.  
  584. >It would be nice to be able to specify initial values for capacitors and 
  585. >inductors. 
  586.  
  587. This can be done. The X vector contains the starting values, and is zeroed 
  588. at setup. However, nothing stops you from running a dc-analysis and then 
  589. running a tran analysis without a setup in between, thereby giving the re- 
  590. sults from the dc-analysis as beginning values for the tran analysis. The 
  591. X vector can also be manually edited. To do this, run setup, then press 
  592. enter for analysis?, which stops the program. Edit the X, and run tran 
  593. analysis without setup. The execution of setup can be avoided by answering 
  594. something else than 'Y' at 'Setup?'. 
  595.  
  596. >I'm interested in any references you used, for algorithms for circuit 
  597. >solving, this is something I've never really looked into before. 
  598.  
  599. A good place to start is to look at a book called 
  600.  
  601. Computer Methods for Circuit Analysis and Design 
  602.  
  603. by Jiri Vlach and Kilshore Singhal (Van Nostrand Reinhold Company 1983, 
  604. ISBN 0-442-28108-0). Check out chapter 4 and 9. For transient analysis, 
  605. (which is normally done by Laplace tranforms when working manually) the 
  606. trapezoidal rule is pretty powerful. Also, for all the theory needed for 
  607. Csim, I have written a report called 
  608.  
  609. A Tutorial on Developing a Simple Circuit Simulating Program 
  610.  
  611. which I can email (ps-file format) to anybody interested upon request. It 
  612. is about 30 pages + 30 pages including this manual and the commented source 
  613. code for Csim. 
  614.  
  615. FINAL REMARK 
  616.  
  617. This simulator is not necessarily completely bug-free, so please report 
  618. to me for any strange behaviour. Note also that the transient analysis 
  619. methods are not necessarily stable for all values of time steps. Try an- 
  620. other time range or time step if this happens. If you get the system error 
  621.    INV Error: 
  622.    Infinite Result 
  623. in any analysis mode, this usually indicates that the component matrix 
  624. cannot be inverted. This error can sometimes be avoided by assigning the 
  625. nodes the values 0...n and the branches the values n+1...m. If this does 
  626. not help, please send me the circuit description you used. 
  627.  
  628. I am happy to provide any further information on this program. Please 
  629. send also some comments on its appearance, suggestions on improvement 
  630. etc. Note that very little syntax checking is done (e.g. no node or 
  631. branch number checks!). I hope this short manual is sufficient, if not 
  632. please ask me directly via email. 
  633.  
  634. copyright Per Stenius, Helsinki University of Technology. 
  635.           email perre@aplac.hut.fi or pstenius@otax.tky.hut.fi 
  636.  
  637. END_DOC 
  638.